#include <climits>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> tall(n + 1);
    vector<int> l(n + 1);
    auto r = l;
    for (int i = 1; i <= n; i++)
    {
        cin >> tall[i];
        for (int j = 1; j < i; j++)
            if (tall[i] > tall[j])
                l[i] = max(l[i], l[j] + 1);
    }
    for (int i = n; i > 0; i--)
        for (int j = n; j > i; j--)
            if (tall[i] > tall[j])
                r[i] = max(r[i], r[j] + 1);

    int res = INT_MAX;
    for (int i = 1; i <= n; i++)
        res = min(res, n - (l[i] + r[i]) - 1);
    cout << res << endl;
    return 0;
}